import { CompletedTaskService } from "@/shared/api/api.completedTask";
import { QueryClient, useMutation, useQuery } from "@tanstack/react-query";

export function useGetAllCompletedTasks() {
    const queryClient = new QueryClient
    const { isLoading, error, data, refetch, isSuccess } =
        useQuery(
            {
                queryKey: ['query-getAllCompletedTasks'],
                queryFn: CompletedTaskService.findAllByUser,
                retry: 3
            }, queryClient
        )

    const errorMessage = error ? "Load disciplines failed" : undefined;

    return {
        completedTasks: data,
        errorMessage,
        refetch,
        isSuccess,
        isLoading
    };
}